package me.minecraft.plugin.pokemondenyconvert.util;

import com.cobblemon.mod.common.pokemon.Pokemon;
import com.cobblemon.mod.common.pokemon.Species;
import lg.minecraft.plugin.cobblemoncore.util.PokemonDataCache;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;

/**
 * @author langle__
 * @version 1.0
 */
@Getter
public class PokemonFilter {

    private final List<String> labelList = new ArrayList<>();
    private final List<Species> speciesList = new ArrayList<>();

    public PokemonFilter(List<String> list) {
        for (String txt : list) {
            String[] split = txt.split(":", 2);
            if (split.length != 2) continue;
            String prefix = split[0];
            if ("label".equalsIgnoreCase(prefix)) {
                labelList.add(split[1]);
            } else if ("species".equalsIgnoreCase(prefix)) {
                Species species = PokemonDataCache.getInstance().getSpeciesByKey(split[1]);
                if (species == null) continue;
                speciesList.add(species);
            }
        }
    }

    public boolean matches(Pokemon pokemon) {
        for (String label : labelList) {
            if (pokemon.hasLabels(label)) {
                return true;
            }
        }
        Species species = pokemon.getSpecies();
        return speciesList.contains(species);
    }

    public boolean isEmpty() {
        return labelList.isEmpty() && speciesList.isEmpty();
    }

}
